#region License, Terms and Conditions
//
// Prawks - Copyright (c) 2007 Atif Aziz. All rights reserved.
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License as published by the Free
// Software Foundation; either version 2.1 of the License, or (at your option)
// any later version.
//
// This library is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
// details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with this library; if not, write to the Free Software Foundation, Inc.,
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 
//
#endregion

namespace Prawks.CodeProvisioning
{
    using System;
    using System.Reflection;
    
    static class TypeCollection
    {
        /// <summary>
        /// Creates a new instance of <see cref="Type"/> array that is 
        /// initialized with the types of a method's parameters.
        /// </summary>
        /// <param name="method">
        /// The method whose parameter types should be used to initialize 
        /// <see cref="Type"/> array.
        /// </param>
        /// <returns>
        /// A <see cref="Type"/> array initialized with the types of the method's parameters.
        /// </returns>

        public static Type[] FromParameters(MethodBase method)
        {
            if (method == null)
                throw new ArgumentNullException("method");

            return FromParameters(method.GetParameters());
        }

        /// <summary>
        /// Creates a new instance of <see cref="TypeCollection"/> that is initialized
        /// with the types of a given array of parameters.
        /// </summary>
        /// <param name="parameters">
        /// The array of paramaters whose types are to be used to initialize 
        /// <see cref="TypeCollection"/>.
        /// </param>
        /// <returns>
        /// A <see cref="Type"/> array initialized with the types of the 
        /// parameters array.
        /// </returns>

        public static Type[] FromParameters(ParameterInfo[] parameters)
        {
            if (parameters == null)
                throw new ArgumentNullException("parameters");

            var types = new Type[parameters.Length];
            
            for (var i = 0; i < parameters.Length; i++)
                types[i] = parameters[i].ParameterType;

            return types;
        }
    }
}
